package server.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import plug.result.RetResponse;
import plug.result.RetResult;
import server.dao.FrmDictionDao;
import server.model.entity.FrmDiction;

import java.util.Comparator;
import java.util.Dictionary;
import java.util.stream.Collectors;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
@RestController
@RequestMapping("v2/api/swiper")
@Api(value = "对外接口（轮播）", tags = {"不需登录(轮播)"})
@CrossOrigin(origins = "*")
public class SwController {
    @Autowired
    FrmDictionDao frmDictionDao;

    @GetMapping("/all")
    @ApiOperation("获得轮播")
    public RetResult getSwiper() {
        return RetResponse.makeOKRsp(frmDictionDao.findByTypeOrderByKeyst("SWIPER")
                .stream().map(FrmDiction::getVal).collect(Collectors.toList()));
    }
    @GetMapping("/List/{type}")
    @ApiOperation("付款方式")
    public RetResult zp(@PathVariable String type) {
        return RetResponse.makeOKRsp(frmDictionDao.findByTypeOrderByKeyst(type).stream()
                .sorted(Comparator.comparing(item->{
                    return Integer.parseInt(item.getVal2());
                })));
    }
    @GetMapping("/zp")
    @ApiOperation("获得转盘")
    public RetResult getZP() {
        return RetResponse.makeOKRsp(frmDictionDao.findByTypeOrderByKeyst("ZP")
                .stream().map(FrmDiction::getVal).collect(Collectors.toList()));
    }
}
